public boolean commonEnd(int[] a, int[] b) {
      boolean x=(a[0]==b[0]);
      boolean y=(a[a.length-1]==b[b.length-1]);
      return x||y;
}